From 314c86901e8aadf731d0ab235ef371248670e940 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 16 Feb 2026 21:18:37 -0800 Subject: account creation flow --- src/routes/(app)/[username]/(profile)/+page.svelte | 59 ++++++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'src/routes/(app)/[username]/(profile)') diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index b9af8756..b37c2009 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -3,10 +3,12 @@ import { onMount } from "svelte"; import Account from "$comp/Account.svelte"; import Balance from "$comp/Balance.svelte"; + import Spinner from "$comp/Spinner.svelte"; import { t } from "$lib/translations"; import { installPrompt, password } from "$lib/store"; - import { afterNavigate, preloadData } from "$app/navigation"; + import { afterNavigate, goto, invalidate, preloadData } from "$app/navigation"; import { page } from "$app/stores"; + import { versions, post, fail } from "$lib/utils"; let { data } = $props(); @@ -17,6 +19,51 @@ let { accounts, subject, rates, user } = $derived(data as any); let { locked } = $derived(user); + let hasArk = $derived(accounts.some((a: any) => a.type === "ark")); + let adding = $state(false); + + let addAccount = async (e) => { + e.preventDefault(); + if (!hasArk) { + goto("/account/new"); + return; + } + + adding = true; + try { + const { getWalletEntropy } = await import("$lib/walletEntropy"); + const prfKey = await getWalletEntropy(); + if (!prfKey) { + goto("/account/seed"); + return; + } + + const [{ HDKey }, { entropyToMnemonic, mnemonicToSeed }, { wordlist }] = await Promise.all([ + import("@scure/bip32"), + import("@scure/bip39"), + import("@scure/bip39/wordlists/english.js"), + ]); + + const entropy = new Uint8Array(prfKey); + const mn = entropyToMnemonic(entropy, wordlist); + const seed = await mnemonicToSeed(mn); + const master = HDKey.fromMasterSeed(seed, versions); + const child = master.derive("m/84'/0'/0'"); + const pubkey = child.publicExtendedKey; + const fingerprint = child.fingerprint.toString(16).padStart(8, "0"); + await post("/account", { + fingerprint, + pubkey, + name: $t("accounts.vault"), + type: "bitcoin", + accountIndex: 0, + }); + invalidate("app:payments"); + } catch (e: any) { + fail(e.message); + } + adding = false; + }; let install = async () => { if (!$installPrompt) return; @@ -64,12 +111,14 @@ {#each accounts as account} {/each} - - - + {/if} + {#if locked} -- cgit v1.2.3